package main

import (
	"encoding/base64"
	"encoding/json"
	"fmt"
	"net/url"
	"time"
)

func encodingcustom() {
	//编码
	data := "enconding test 孔宥芯！"
	fmt.Printf("%s\n", []byte(data))
	encodeToString := base64.StdEncoding.EncodeToString([]byte(data))
	fmt.Printf("%s \n", encodeToString)
	// 解码
	decodeString, err := base64.StdEncoding.DecodeString(encodeToString)
	if err != nil {
		fmt.Printf("Error :  %s\n", err)
	}
	fmt.Printf("%s\n", decodeString)
}
func urlDecodeEncoder() {
	//编码
	var urladdr = "https://instance-dev.tvunetworks.com/instance-manage/index.html#/instancemanage/instance"
	var encode = url.QueryEscape(urladdr)
	fmt.Printf(" encoder:  %s\n", encode)
	//解码
	queryUnescape, err := url.QueryUnescape(encode)
	if err != nil {
		fmt.Printf("Error :  %s\n", err)
	}
	fmt.Printf(" queryUnescape: %s\n", queryUnescape)
}

type Persion struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
	City string `json:"city"`
}

func jsondecoderencoder() {
	var person Persion = Persion{
		Name: "33孔",
		Age:  2,
		City: "男",
	}
	marshal, err := json.Marshal(person)
	if err != nil {
		fmt.Printf("Error :  %s\n", err)
	}
	fmt.Printf("json deocer marshal : %s ,string mar: %s \n", marshal, string(marshal))
	//解码
	var decoderPerson Persion
	err = json.Unmarshal(marshal, &decoderPerson)
	if err != nil {
		fmt.Printf(" 解码 Error :  %s\n", err)
		return
	}
	fmt.Printf("json deocer unmarshal : %+v \n", decoderPerson)

	var jsonstring = "{\n    \"Buffer\": 2000,\n    \"ConstDelay\": 0,\n    \"Format\": \"1080i5994\",\n    \"Preview\": \"WebRTC\",\n    \"Restriction\": {\n        \"Identity\": {\n            \"RootGroupId\": \"16d219d093fe4d268a721bbce00d7de8\",\n            \"UserEmail\": \"charm@tvu.com\",\n            \"UserId\": \"f9bfa05de53a42c8bd5272f70650670f\"\n        },\n        \"PreferredCloud\": {\n            \"Region\": \"us-east-1\",\n            \"Vendor\": \"Physical\"\n        },\n        \"Strategy\": \"SpecifiedCloudOnly\"\n    },\n    \"SourceType\": \"Youtube\",\n    \"SourceUrl\": \"https://www.youtube.com/watch?v=Ev19uXOWBNg\",\n    \"TraceId\": \"0HN6NJTQ4K11I:00000030\"\n}"
	personnew := buffsiond{}
	json.Unmarshal([]byte(jsonstring), &personnew)
	fmt.Printf("json deocer unmarhsal : %+v \n", personnew)
}

type buffsiond struct {
	Buffer      int    `json:"Buffer"`
	ConstDelay  int    `json:"ConstDelay"`
	Format      string `json:"Format"`
	Preview     string `json:"Preview"`
	Restriction struct {
		Identity struct {
			RootGroupId string `json:"RootGroupId"`
			UserEmail   string `json:"UserEmail"`
			UserId      string `json:"UserId"`
		} `json:"Identity"`
		PreferredCloud struct {
			Region string `json:"Region"`
			Vendor string `json:"Vendor"`
		} `json:"PreferredCloud"`
		Strategy string `json:"Strategy"`
	} `json:"Restriction"`
	SourceType string `json:"SourceType"`
	SourceUrl  string `json:"SourceUrl"`
	TraceId    string `json:"TraceId"`
}
type jira struct {
	Data struct {
		Jira struct {
			EcosystemFirstSeenOnIssueView time.Time `json:"ecosystemFirstSeenOnIssueView"`
			HasAdministerPermission       bool      `json:"hasAdministerPermission"`
			HasUserPickerPermission       bool      `json:"hasUserPickerPermission"`
		} `json:"jira"`
		MediaContext struct {
			UserToken   interface{} `json:"userToken"`
			UploadToken struct {
				Typename            string `json:"__typename"`
				EndpointUrl         string `json:"endpointUrl"`
				Token               string `json:"token"`
				TargetCollection    string `json:"targetCollection"`
				TokenDurationInMins int    `json:"tokenDurationInMins"`
				ClientId            string `json:"clientId"`
			} `json:"uploadToken"`
			ReadToken struct {
				ClientId        string `json:"clientId"`
				EndpointUrl     string `json:"endpointUrl"`
				TokensWithFiles []struct {
					Files []struct {
						IssueId              string `json:"issueId"`
						AttachmentId         string `json:"attachmentId"`
						AttachmentMediaApiId string `json:"attachmentMediaApiId"`
					} `json:"files"`
					Token string `json:"token"`
				} `json:"tokensWithFiles"`
				TokenLifespanInSeconds int `json:"tokenLifespanInSeconds"`
			} `json:"readToken"`
		} `json:"mediaContext"`
		ViewIssue struct {
			CanCreateSubTask bool `json:"canCreateSubTask"`
			CanExportIssue   bool `json:"canExportIssue"`
			Comments         struct {
				Nodes []struct {
					Id     string `json:"id"`
					Author struct {
						AccountId   string `json:"accountId"`
						DisplayName string `json:"displayName"`
						AvatarUrl   string `json:"avatarUrl"`
					} `json:"author"`
					UpdateAuthor struct {
						AccountId   string `json:"accountId"`
						DisplayName string `json:"displayName"`
						AvatarUrl   string `json:"avatarUrl"`
					} `json:"updateAuthor"`
					JiraCommentVisibility         interface{} `json:"jiraCommentVisibility"`
					Created                       int64       `json:"created"`
					Updated                       int64       `json:"updated"`
					JsdPublic                     bool        `json:"jsdPublic"`
					BodyAdf                       string      `json:"bodyAdf"`
					JsdAuthorCanSeeRequest        bool        `json:"jsdAuthorCanSeeRequest"`
					IsDeleted                     interface{} `json:"isDeleted"`
					ParentId                      interface{} `json:"parentId"`
					Replies                       interface{} `json:"replies"`
					EventOccurredAt               interface{} `json:"eventOccurredAt"`
					JsdIncidentActivityViewHidden interface{} `json:"jsdIncidentActivityViewHidden"`
				} `json:"nodes"`
				TotalCount        int         `json:"totalCount"`
				StartIndex        interface{} `json:"startIndex"`
				RootCommentsCount interface{} `json:"rootCommentsCount"`
			} `json:"comments"`
			Ecosystem struct {
				ActivityPanels []interface{} `json:"activityPanels"`
				ContextPanels  []struct {
					Name   string `json:"name"`
					Iframe struct {
						AddonKey  string `json:"addonKey"`
						ModuleKey string `json:"moduleKey"`
						Options   string `json:"options"`
					} `json:"iframe"`
					Icon struct {
						Url string `json:"url"`
					} `json:"icon"`
					Content string      `json:"content"`
					Status  interface{} `json:"status"`
					Type    string      `json:"type"`
				} `json:"contextPanels"`
				Forge struct {
					Panels []interface{} `json:"panels"`
				} `json:"forge"`
			} `json:"ecosystem"`
			ContentPanels struct {
				Edges []struct {
					Node struct {
						Name                    string `json:"name"`
						AddonKey                string `json:"addonKey"`
						ModuleKey               string `json:"moduleKey"`
						Options                 string `json:"options"`
						IconUrl                 string `json:"iconUrl"`
						Tooltip                 string `json:"tooltip"`
						Type                    string `json:"type"`
						IsShownByDefault        bool   `json:"isShownByDefault"`
						WasManuallyAddedToIssue bool   `json:"wasManuallyAddedToIssue"`
					} `json:"node"`
				} `json:"edges"`
			} `json:"contentPanels"`
			LegacyContentPanels struct {
				Edges []struct {
					Node struct {
						Name                    string      `json:"name"`
						AddonKey                string      `json:"addonKey"`
						ModuleKey               string      `json:"moduleKey"`
						Options                 string      `json:"options"`
						IconUrl                 interface{} `json:"iconUrl"`
						Tooltip                 interface{} `json:"tooltip"`
						Type                    string      `json:"type"`
						IsShownByDefault        bool        `json:"isShownByDefault"`
						WasManuallyAddedToIssue bool        `json:"wasManuallyAddedToIssue"`
					} `json:"node"`
				} `json:"edges"`
			} `json:"legacyContentPanels"`
			HasCustomisedContentPanels bool `json:"hasCustomisedContentPanels"`
			LegacyRightWebPanels       struct {
				Edges []struct {
					Node struct {
						Name      string      `json:"name"`
						Status    interface{} `json:"status"`
						AddonKey  string      `json:"addonKey"`
						ModuleKey string      `json:"moduleKey"`
						Options   string      `json:"options"`
						Content   interface{} `json:"content"`
					} `json:"node"`
				} `json:"edges"`
			} `json:"legacyRightWebPanels"`
			TotalAttachmentsCount int `json:"totalAttachmentsCount"`
			ContainersByType      struct {
				Typename   string `json:"__typename"`
				Containers []struct {
					ContainerType string `json:"containerType"`
					Items         struct {
						Nodes []struct {
							Type        string `json:"type"`
							FieldItemId string `json:"fieldItemId"`
						} `json:"nodes"`
					} `json:"items"`
				} `json:"containers"`
			} `json:"containersByType"`
			RemoteLinks struct {
				IsLinkingEnabled   bool          `json:"isLinkingEnabled"`
				RemoteLinkedIssues []interface{} `json:"remoteLinkedIssues"`
			} `json:"remoteLinks"`
		} `json:"viewIssue"`
		JiraSettings struct {
			NewIssueViewTransitionSettings struct {
				ShouldDelayChangeboarding           bool   `json:"shouldDelayChangeboarding"`
				NewIssueViewTransitionLockingStatus string `json:"newIssueViewTransitionLockingStatus"`
			} `json:"newIssueViewTransitionSettings"`
		} `json:"jiraSettings"`
		Permissions []struct {
			Key            string `json:"key"`
			HavePermission bool   `json:"havePermission"`
		} `json:"permissions"`
		Project struct {
			Id                   string `json:"id"`
			NewIssueViewLockedIn bool   `json:"newIssueViewLockedIn"`
			IssueTypes           []struct {
				Id      string `json:"id"`
				Name    string `json:"name"`
				IconUrl string `json:"iconUrl"`
				Subtask bool   `json:"subtask"`
			} `json:"issueTypes"`
		} `json:"project"`
	} `json:"data"`
}
